package com.huyaanalysisplatform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huyaanalysisplatform.entity.TContribution;
import com.huyaanalysisplatform.entity.TFan;
import com.huyaanalysisplatform.mapper.TFanMapper;
import com.huyaanalysisplatform.service.TFanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Huadi Group 12
 * @since 2021-08-01
 */
@Service
public class TFanServiceImpl extends ServiceImpl<TFanMapper, TFan> implements TFanService {


    public Map queryFans(Map<String, Long> map) {
        List<Map> fan = new ArrayList<>();
        Long roomNumber = map.get("roomNumber");
        QueryWrapper<TFan> queryWrapper = new QueryWrapper<TFan>()
                .eq("roomNumber", roomNumber)
                .orderByDesc("score");
        List<TFan> tContributions = this.list(queryWrapper);
        for (int i = 0; i < tContributions.size(); i++) {
            Map map1 = new HashMap();
            map1.put("score", tContributions.get(i).getScore());
            map1.put("nick", tContributions.get(i).getNick());
            map1.put("number", i + 1);
            fan.add(map1);
        }
        Map map1 = new HashMap();
        map1.put("tableData", fan);
        return map1;
    }
}
